<template>
    <ZZDialog class="analysisBox" title="空间分析" @close="callbackClose()">
    <div class="basicbox" v-if="currentType==''">
        <div class="btn-group">
            <div id="btn_goto_rzfx" class="tool-btn" @click="analysisType('rzfx')">
                <div class="tool-thum" style="background: #dd751b;"><img src="./img/rzfx.svg" alt="日照分析"></div>
                <span class="btn_none"> 日照分析 </span>
            </div>


            <div id="btn_goto_ksy" class="tool-btn" @click="analysisType('ksy')">
                <div class="tool-thum" style="background: #c092fe;"><img src="./img/ksy.svg" alt="可视域"></div>
                <span class="btn_none"> 可视域 </span>
            </div>


            <div id="btn_goto_flfx" class="tool-btn" @click="analysisType('flfx')">
                <div class="tool-thum" style="background: #88b8ff;"><img src="./img/flfx.svg" alt="方量分析"></div>
                <span class="btn_none"> 方量分析 </span>
            </div>

            <div id="btn_goto_dxkw" class="tool-btn" @click="analysisType('dxkw')">
                <div class="tool-thum" style="background: #55d5a0;"><img src="./img/dxkw.svg" alt="地形开挖"></div>
                <span class="btn_none"> 地形开挖 </span>
            </div>

            <div id="btn_goto_dbtm" class="tool-btn" @click="analysisType('dbtm')">
                <div class="tool-thum" style="background: #b85555;"><img src="./img/dbtm.svg" alt="地表透明"></div>
                <span class="btn_none"> 地表透明 </span>
            </div>

            <div id="btn_goto_pdpx" class="tool-btn" @click="analysisType('pdpx')">
                <div class="tool-thum" style="background: #3de3f4;"><img src="./img/pdpx.svg" alt="坡度坡向"></div>
                <span class="btn_none"> 坡度坡向 </span>
            </div>

            <div id="btn_goto_mxpq" class="tool-btn" @click="analysisType('mxpq')">
                <div class="tool-thum" style="background: #37bc41;"><img src="./img/mxpq.svg" alt="模型剖切">
                </div>
                <span class="btn_none"> 模型剖切 </span>
            </div>

            <div id="btn_goto_mxyp" class="tool-btn" @click="analysisType('mxyp')">
                <div class="tool-thum" style="background: #95d333;"><img src="./img/mxyp.svg" alt="模型压平"></div>
                <span class="btn_none"> 模型压平 </span>
            </div>

            <div id="btn_goto_mxcj" class="tool-btn" @click="analysisType('mxcj')">
                <div class="tool-thum" style="background: #babc31;"><img src="./img/mxcj.svg" alt="模型裁剪"></div>
                <span class="btn_none"> 模型裁剪 </span>
            </div>
        </div>
    </div>

    <!-- 日照分析 -->
    <div id="sunAnal" class="mainbox" v-if="currentType ==='rzfx'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_rzfx_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis()"></i>
                <span>日照分析</span>
            </div>
            <div id="btn_rzfx_clear" class="del" @click="destroyRZFX()">
                <i class="fa fa-trash-o" @click="destroyRZFX()"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:模拟设定时间范围内的太阳光照效果。
            </div>
            <div class="rowview clearfix">
                <span>日期选择:</span>
                <el-date-picker
                    v-model="rzfx_Date"
                    type="date"
                    placeholder="选择日期"
                    style="width: 200px;"
                />
            </div>
            <div class="rowview clearfix">
                <span>开始时间:</span>
                <el-time-picker v-model="rzfx_StartTime" placeholder="开始时间" style="width: 200px;"/>
            </div>
            <div class="rowview clearfix">
                <span>结束时间:</span>
                <el-time-picker v-model="rzfx_EndTime" placeholder="结束时间" style="width: 200px;"/>
            </div>
            <div class="rowview clearfix center">
                <el-button @click="startRZFX(rzfx_Date,rzfx_StartTime,rzfx_EndTime)">播放</el-button>
                <el-button @click="stopRZFX()">暂停</el-button>
            </div>
            <div class="rowview clearfix">
                <span>当前时间:</span><span id="lbl_rzfx_nowTime">{{ currentTime }}</span>
            </div>
        </div>
    </div>

    <!-- 可视域 -->
    <div id="ksyAnal" class="mainbox" v-if="currentType=='ksy'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_ksy_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>可视域</span>
            </div>
            <div id="btn_ksy_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:单击按钮后在图上绘制，红色代表不可视，绿色代表可视。
            </div>

            <div class="rowview clearfix">
                <span>水平张角:</span>
                <el-slider v-model="ksy_horizontalAngle" :max=120 :min=1 style="width: 200px;" />
            </div>
            <div class="rowview clearfix">
                <span>垂直张角:</span>
                <el-slider v-model="ksy_verticalAngle" :max=90 :min=1 style="width: 200px;"/>
            </div>
            <div class="rowview clearfix">
                <span>视角距离:</span>
                <el-slider v-model="ksy_distance" :max=5000 :min=1 style="width: 200px;"/>
            </div>
            <div class="rowview clearfix">
                <span>视椎框线:</span>
                <el-checkbox v-model="ksy_DebugFrustum" label="显示框线" />
            </div>
            <div class="rowview clearfix center">
                <el-button style="margin-bottom: 10px;" @click="startKSY">添加可视域</el-button>
            </div>
        </div>
    </div>

    <!-- 方量分析 -->
    <div id="flAnal" class="mainbox" v-if="currentType=='flfx'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_flfx_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>方量分析</span>
            </div>
            <div id="btn_flfx_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:请首先单击 “绘制区域” 按钮，再在图上绘制分析区域。
            </div>
            <div class="rowview clearfix center">
                <el-button @click="startFLFX" >
                    <i class="fa fa-edit"></i>
                    绘制分析区域
                </el-button>
            </div>
            <div class="rowview clearfix">
                <span>基准面高:</span>
                <el-tooltip content="计量单位：米" placement="right">
                   <el-input-number  controls-position="right" style="width:110px"
                   v-model="flfx_Height"  @change="heightChange('h')"
                   size="small" :min="1" :max="100" :step="0.1"/> 
                </el-tooltip>
                <el-button size="mini" style="margin-left: 15px;" @click="pickHeight">点选高度</el-button>
            </div>

            <div class="rowview clearfix">
                <span>围墙底高:</span>
                <el-tooltip content="计量单位：米" placement="right">
                   <el-input-number   controls-position="right" 
                   v-model="flfx_MinHeight" @change="heightChange('min')"
                   size="small" :min="1" :max="100" :step="0.1"/> 
                </el-tooltip>
                （可选）
            </div>
            <div class="rowview clearfix" style="margin-bottom: 10px;">
                <span>围墙顶高:</span>
                <el-tooltip content="计量单位：米" placement="right">
                   <el-input-number   controls-position="right" 
                   v-model="flfx_MaxHeight" @change="heightChange('max')"
                   size="small" :min="1" :max="100" :step="0.1"/> 
                </el-tooltip>
                （可选）
            </div>
        </div>

    </div>

    <!-- 地形开挖 -->
    <div id="dxAnal" class="mainbox" v-if="currentType=='dxkw'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_dxkw_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>地形开挖</span>
            </div>
            <div id="btn_dxkw_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:请首先单击 “绘制区域” 按钮，再在图上绘制开挖区域。
            </div>
            <div class="rowview clearfix">
                <span>开挖深度:</span>
                <el-tooltip content="计量单位：米" placement="right">
                   <el-input-number  controls-position="right" style="width: 140px;"
                   v-model="dxkw_clipHeight"
                   size="small" :min="1" :max="100" :step="1"/> 
                </el-tooltip>
            </div>
            <div class="rowview clearfix center">
                <el-button style="margin-bottom:10px" @click="startDXKW">
                    <i class="fa fa-edit"></i>
                    绘制开挖矩形
                </el-button>
            </div>
        </div>
    </div>

    <!-- 地表透明 -->
    <div id="dbAnal" class="mainbox" v-if="currentType=='dbtm'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_dbtm_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>地表透明</span>
            </div>
            <div id="btn_dbtm_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:可以透明地表，进入地下模式，可以看地下管网等数据。
            </div>
            <div class="rowview clearfix" style="margin-bottom:5px">
                <span>地表透明度:</span>
                <el-slider v-model="dbtm_alpha" :max=1.0 :min=0.0 :step="0.1" size="small" style="width: 100px;"/>
            </div>
            <div class="rowview clearfix">
                <span>开启状态:</span>
                <el-checkbox v-model="dbtm_Underground" label="开启地表透明" size="large" @change="changeDBTM" />
            </div>
        </div>
    </div>

    <!-- 坡度坡向 -->
    <div id="tsAnal" class="mainbox" v-if="currentType=='pdpx'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_pdpx_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>坡度坡向</span>
            </div>
            <div id="btn_pdpx_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:单击按钮后在图上绘制区域。
            </div>
            <div class="rowview clearfix ">   
                <span>插值数:</span>
                <el-tooltip content="计量单位：米" placement="right">
                   <el-input-number  controls-position="right" style="width:170px"
                   v-model="pdpx_SplitNum"
                   size="small" :min="1" :max="9999" :step="1"/> 
                </el-tooltip>
            </div>
            <div class="rowview clearfix center" style="margin-bottom:10px">
                <el-button style="padding:auto" @click="startPDPX">绘制区域</el-button>
            </div>
        </div>
    </div>

    <!-- 模型剖切 -->
    <div id="mxpqAnal" class="mainbox" v-if="currentType=='mxpq'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_mxpq_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>模型剖切</span>
            </div>
            <div id="btn_mxpq_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示:请先图上点选模型后，设置剖切方向及距离。
            </div> 
            <div class="rowview clearfix">
                <span>选择模型:</span>
                <el-button size="small" @click="select_mxpq_tiles()">图上点选</el-button>
                <span style="margin-left: 20px;">{{ mxpq_tile }}</span>
            </div>
            <div class="rowview clearfix">
                <span>按线剖切:</span>
                <el-button size="small" @click="draw_mxpq_line()">绘制线</el-button>
            </div>
            <div class="rowview clearfix">
                <span style="width: 100px;">剖切方向:</span>
                <div>
                    <el-button size="mini" @click="startMXPQ('ding')">顶</el-button>
                    <el-button size="mini" @click="startMXPQ('di')">底</el-button>
                    <el-button size="mini" @click="startMXPQ('dong')">东</el-button>
                    <el-button size="mini" @click="startMXPQ('nan')">南</el-button>
                    <el-button size="mini" @click="startMXPQ('xi')">西</el-button>
                    <el-button size="mini" @click="startMXPQ('bei')">北</el-button>
                </div>
            </div>
            <div class="rowview clearfix">
                <span>剖切距离:</span>
                <el-slider v-model="mxpq_Distance" @input="changeMXPQ()"
                :max=100 :min=-100 :step="1" 
                 size="small" style="width: 200px;"
                />
            </div>
        </div>
    </div>

    <!-- 模型压平 -->
    <div id="mxypAnal" class="mainbox" v-if="currentType=='mxyp'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_mxyp_destory" class="fa fa-chevron-left backmenu" @click="currentType = ''"></i>
                <span>模型压平</span>
            </div>
            <div id="btn_mxyp_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">

            <div class="rowview clearfix tip">
                提示: 模型压平只支持部分无着色器的3dtiles数据。
            </div>
            <div class="rowview clearfix">
                <span>选择模型:</span>
                <el-button size="small" @click="select_mxyp_tile()">图上点选</el-button>
                <span style="margin-left: 20px;">{{ mxyp_tile }}</span>
            </div>
            <div class="rowview clearfix">
                <span>压平高度:</span>
                <el-tooltip content="计量单位：米" placement="right">
                   <el-input-number  controls-position="right" style="width:140px" 
                   v-model="mxyp_flatHeight"  @change="change_mxyp_height()"
                   size="small" :min="0" :max="100" :step="1"/> 
                </el-tooltip>
            </div>

            <div class="rowview clearfix center">
                <el-button style="margin-bottom:10px" @click="startMXYP()">
                    <i class="fa fa-edit"></i>
                    绘制压平区域
                </el-button>
            </div>

        </div>
    </div>

    <!-- 模型裁剪 -->
    <div id="mxcjAnal" class="mainbox" v-if="currentType=='mxcj'">
        <div class="headbox">
            <div class="headtitle">
                <i id="btn_mxcj_destory" class="fa fa-chevron-left backmenu" @click="backAnalysis"></i>
                <span>模型裁剪</span>
            </div>
            <div id="btn_mxcj_clear" class="del" @click="destoryAnalysis">
                <i class="fa fa-trash-o" @click="destoryAnalysis"></i>
                <span>清除</span>
            </div>
        </div>
        <div class="mainInfo">
            <div class="rowview clearfix tip">
                提示: 模型裁剪只支持部分无着色器的3dtiles数据。
            </div>
            <div class="rowview clearfix">
                <span>选择模型:</span>
                <el-button size="small" @click="select_mxcj_tile()">图上点选</el-button>
                <span style="margin-left: 20px;">{{ mxcj_tile }}</span>
            </div>
            <div class="rowview clearfix">
                <span>裁剪方式:</span>
                <el-radio-group v-model="mxcj_Type" >
                    <el-radio style="color: #fff;" :label="0">内裁剪</el-radio>
                    <el-radio style="color: #fff;" :label="1">外裁剪</el-radio>
                </el-radio-group>
            </div>
            <div class="rowview clearfix center">
                <el-button style="margin-bottom: 10px;" @click="startMXCJ">
                    <i class="fa fa-edit"></i>
                    绘制裁剪区域
                </el-button>
            </div>
        </div>
    </div>

    </ZZDialog>
</template>

<script>
import ZZDialog from '../../../common/ZZDialog.vue'
import { Message } from 'element-ui'
import wallimg from './img/textures/excavationregion_side.jpg'
import topimg from './img/textures/excavationregion_top.jpg'

export default {
  components: {
        ZZDialog
  },
  data() {
    return {
      currentType: "",
      
      rzfx_Date: new Date(2023, 11, 22),
      rzfx_StartTime: new Date(2023, 12, 22, 8, 0),
      rzfx_EndTime: new Date(2023, 12, 22, 18, 0),
      currentTime: '',
      
      ksy_horizontalAngle: 90,
      ksy_verticalAngle: 60,
      ksy_distance: 10,
      ksy_DebugFrustum: true,
      
      flfx_Height: 0,
      flfx_MinHeight: 0,
      flfx_MaxHeight: 0,
      flfx_chkUnderground: false,

      dxkw_clipHeight: 1,

      dbtm_alpha: 0.5,
      dbtm_Underground: false,

      pdpx_SplitNum: 10,

      mxpq_Distance: 0,
      mxpq_tile: '未选择',

      mxyp_flatHeight: 0,
      mxyp_tile: '未选择',

      mxcj_Type: 0,
      mxcj_tile: '未选择'
    };
  },
  beforeMount(){ 
    this.viewer = this.$store.state.viewer
  },
  mounted(){
    this.currentTime = this.getcurrentTime()
  },
  methods:{
    analysisType(type) {
        this.currentType = type
    },
    backAnalysis() {
        this.destoryAnalysis()
        if(this.currentType==='rzfx')this.destroyRZFX()
        this.currentType= ''
    },
    // 日照分析
    startRZFX(startDate,endDate) {
        this.viewer.clock.shouldAnimate = true;
        if (this.stopTime) {
            this.viewer.clock.currentTime = this.stopTime;
        } else {
            this.viewer.scene.globe.enableLighting = true;
            this.viewer.shadows = true;
            this.viewer.clock.startTime = Cesium.JulianDate.fromDate(startDate);
            this.viewer.clock.currentTime = Cesium.JulianDate.fromDate(startDate);
            this.viewer.clock.stopTime = Cesium.JulianDate.fromDate(endDate);
            this.viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
            this.viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER;
            this.viewer.clock.multiplier = 1600;
        }
    },
    stopRZFX() {
        this.stopTime = this.viewer.clock.currentTime;
        this.viewer.clock.shouldAnimate = false;
    },
    destroyRZFX() {
        this.viewer.clock.clockRange = Cesium.ClockRange.UNBOUNDED;
        this.viewer.clock.multiplier = 1;
        this.viewer.shadows = false;
        this.rzfx_Date = new Date(2023, 11, 22)
        this.rzfx_StartTime = new Date(2023, 12, 22, 8, 0)
        this.rzfx_EndTime = new Date(2023, 12, 22, 18, 0)
        this.currentTime = this.getcurrentTime()
    },

    // 可视域
    startKSY() {
        this.destoryAnalysis()
        this.viewer.zz.analyseFactory
        .create('ViewShed', {
        horizontalAngle: this.ksy_horizontalAngle,
        verticalAngle: this.ksy_verticalAngle,
        distance: this.ksy_distance,
        debugFrustum: this.ksy_DebugFrustum,
        offsetHeight: 1.5, //加人的身高等因素，略微抬高一些
        })
        .then((id) => {
        console.log("当前分析为：可视域分析")
        this.currentAnalysisObj = this.viewer.zz.analyseFactory.get(id);
        this.ksy_distance = this.currentAnalysisObj?._options?.distance || 10.0;
        })
        .catch(() => console.log('cancel'));
    },
    getcurrentTime() {
        let getTime = new Date().getTime();
        let time = new Date(getTime); 
        let year = time.getFullYear(); // 年
        let month = (time.getMonth() + 1).toString().padStart(2, '0'); // 月
        let date = time.getDate().toString().padStart(2, '0'); // 日
        let hour = time.getHours().toString().padStart(2, '0'); // 时
        let minute = time.getMinutes().toString().padStart(2, '0'); // 分
        let second = time.getSeconds().toString().padStart(2, '0'); // 秒
        return (
            year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
        )
    },

    // 方量分析
    startFLFX() {
        this.destoryAnalysis()
        this.viewer.zz.analyseFactory
            .create('MeasureVolume', {
                splitNum: 6, //面内插值次数，控制精度[注意精度越大，分析时间越长]
                onStart: ()=> {},
                onEnd: ()=> { 
                    this.flfx_Height = Number(this.currentAnalysisObj.height.toFixed(2))
                    this.flfx_MinHeight = Number(this.currentAnalysisObj.minHeight.toFixed(2))
                    this.flfx_MaxHeight = Number(this.currentAnalysisObj.maxHeight.toFixed(2))
                },
                style: {color: '#FFFF00'},
            })
            .then((id) => {
                console.log("当前分析为：方量分析")
                this.currentAnalysisObj = this.viewer.zz.analyseFactory.get(id);
            })
            .catch(() => console.log('cancle'));
    },
    heightChange(type) {
        if(this.currentAnalysisObj == undefined){
            return
        }
        switch (type) {
            case 'h':
            this.currentAnalysisObj.height = this.flfx_Height
                break;
            case 'min':
                if(this.flfx_MinHeight > Number(this.currentAnalysisObj)){
                    Message({
                        message: '墙底部高度不能高于基准面高',
                        type: 'error',
                    })
                }
                this.currentAnalysisObj.minHeight = this.flfx_MinHeight
                break;
            case 'max':
            if(this.flfx_MaxHeight < Number(this.currentAnalysisObj.height)){
                    Message({
                        message: '墙顶部高度不能低于基准面高',
                        type: 'error',
                    })
                }
                this.currentAnalysisObj.maxHeight = this.flfx_MaxHeight
                break;
            default:
                break;
        }
    },
    pickHeight() {
        if(!this.currentAnalysisObj){
            return
        } 
        this.currentAnalysisObj.selecteHeight(()=>{
            this.flfx_Height = Number(this.currentAnalysisObj.height.toFixed(2))
            this.flfx_MinHeight =  Number(this.currentAnalysisObj.minHeight.toFixed(2))
            this.flfx_MaxHeight =  Number(this.currentAnalysisObj.maxHeight.toFixed(2))
        })
    },

    // 地形开挖
    startDXKW() {
        this.destoryAnalysis()
        this.currentAnalysisObj = new zz3d.analysi.TerrainClipEx(this.viewer, {
            height: this.dxkw_clipHeight,
            splitNum: 50, //wall边界插值数
            wallImg: wallimg,
            bottomImg: topimg
        });
        console.log("当前分析为：地形开挖")
    },

    // 地表透明
    changeDBTM() {
        this.currentAnalysisObj = new zz3d.analysi.Underground(this.viewer, {
            alpha: this.dbtm_alpha,
            enable: this.dbtm_Underground,
        });
        if(this.dbtm_Underground) console.log("当前分析为：地形开挖")
    },

    // 坡度坡向
    startPDPX() {
        this.destoryAnalysis()
        this.viewer.zz.analyseFactory
            .create('Slope', {
                type:"polygon",  //进行绘制面操作
                style:{          //绘制面样式
                    "color": "#29cf34",
                    "opacity": 0.3,
                    "clampToGround": true
                },
                onStart:()=>{}, //分析开始回调
                onEnd:()=>{},     //分析结束回调
                point: {         //分析结果中分析基点样式
                    show: true,
                    pixelSize: 9,
                    color: Cesium.Color.RED.withAlpha(0.5),
                },
                arrow: {         //分析结果中箭头样式
                    show: true,
                    scale: 0.3, //箭头长度的比例（范围0.1-0.9）
                    width: 15, //箭头宽度
                    color: Cesium.Color.YELLOW
                }
            })
            .then((id) =>{
                console.log("当前分析为：坡度坡向")
                this.currentAnalysisObj = this.viewer.zz.analyseFactory.get(id);
            })
            .catch(() => {
                console.log('cancel');
            });
    },

    // 模型刨切
    startMXPQ(type) {
        if(!this.currentAnalysisObj){
            Message({
                message: '请选择模型',
                type: 'error',
            })
            return
        }
        switch (type) {
            case 'ding':
            this.currentAnalysisObj.type = zz3d.tiles.TilesClipPlan.Type.Z;
                break;
            case 'di':
            this.currentAnalysisObj.type = zz3d.tiles.TilesClipPlan.Type.ZR;
                break;
            case 'dong':
            this.currentAnalysisObj.type = zz3d.tiles.TilesClipPlan.Type.X;
                break;
            case 'nan':
            this.currentAnalysisObj.type = zz3d.tiles.TilesClipPlan.Type.XR;
                break;
            case 'xi':
            this.currentAnalysisObj.type = zz3d.tiles.TilesClipPlan.Type.Y;
                break;
            case 'bei':
            this.currentAnalysisObj.type = zz3d.tiles.TilesClipPlan.Type.YR;
                break;
        
            default:
                break;
        }
    },
    draw_mxpq_line() {
        this.viewer.zz.draw.startDraw({
            type: 'polyline',
            config: {
                maxPointNum: 2
            },
            style: {
                color: '#007be6',
                opacity: 0.8,
                outline: false,
            },
            success: (entity)=> { //绘制成功后回调 
                let points = this.viewer.zz.draw.getPositions(entity);
                this.viewer.zz.draw.deleteAll();
                if(!this.currentAnalysisObj){
                    Message({
                        message: '请选择模型',
                        type: 'error',
                    })
                    return
                }
                this.currentAnalysisObj.clipByPoints(points);
            }
        });
    },
    select_mxpq_tiles() {
        this.viewer.zz.draw.startDraw({
                type: "point",
                style: {
                    color: "#007be6",
                },
                success: (entity)=> { //绘制成功后回调
                    let positions = this.viewer.zz.draw.getPositions(entity);
                    this.viewer.zz.draw.deleteAll();
                    let tileset = zz3d.tileset.pick3DTileset(this.viewer, positions);//拾取绘制返回的模型
                    if (!tileset) {
                        Message({
                            message: '请选择模型',
                            type: 'error',
                        })
                        return;
                    }
                    this.currentAnalysisObj = new zz3d.tiles.TilesClipPlan(tileset);
                    this.mxpq_tile = this.currentAnalysisObj._tileset.name
                }
            });
    },
    changeMXPQ() {
        if(!this.currentAnalysisObj){
            return
        }
        this.currentAnalysisObj.distance = this.mxpq_Distance
    },

    // 模型压平
    startMXYP() {
        this.viewer.zz.draw.deleteAll();
        this.viewer.zz.draw.startDraw({
            type: "polygon",
            style: {
                color: "#007be6",
                opacity: 0.5,
                clampToGround: false,
            },
            success:  (entity)=> {
                //绘制成功后回调
                let positions = this.viewer.zz.draw.getPositions(entity);
                //显示边界线处理
                var coords = this.viewer.zz.draw.getCoordinates(entity);
                coords.push(coords[0]);
                this.viewer.zz.draw.deleteAll();
                this.viewer.zz.draw.addPolyline(coords, {
                    color: "#ffffff",
                    clampToGround: true,
                    width: 2,
                });
                this.currentAnalysisObj.addArea(positions, undefined, this.mxyp_flatHeight);
            },
        });
    },
    select_mxyp_tile() {
        this.viewer.zz.draw.startDraw({
                type: "point",
                style: {
                    color: "#007be6",
                },
                success: (entity)=> { //绘制成功后回调
                    let positions = this.viewer.zz.draw.getPositions(entity);
                    this.viewer.zz.draw.deleteAll();
                    let tileset = zz3d.tileset.pick3DTileset(this.viewer, positions);//拾取绘制返回的模型
                    if (!tileset) {
                        Message({
                            message: '请选择模型',
                            type: 'error',
                        })
                        return;
                    }
                    this.currentAnalysisObj = new zz3d.tiles.createFlatObj({
                        viewer: this.viewer,
                        tileset: tileset,
                    });
                    this.mxyp_tile = tileset.name
                }
            });
    },

    // 模型裁剪
    startMXCJ() {
        this.viewer.zz.draw.startDraw({
            type: "polygon",
            style: {
                color: "#007be6",
                opacity: 0.5,
                clampToGround: true,
            },
            success:  (entity)=> { //绘制成功后回调
                var points = this.viewer.zz.draw.getPositions(entity);
                this.viewer.zz.draw.deleteAll();
                this.currentAnalysisObj.clipByPoints(points, {
                    unionClippingRegions: this.mxcj_Type === 0 ? false : true,
                    edgeColor: Cesium.Color.GREY,
                    edgeWidth: 2.0,
                });
            }
        });
    },
    select_mxcj_tile() {
        this.viewer.zz.draw.startDraw({
                type: "point",
                style: {
                    color: "#007be6",
                },
                success: (entity)=> { //绘制成功后回调
                    let positions = this.viewer.zz.draw.getPositions(entity);
                    this.viewer.zz.draw.deleteAll();
                    let tileset = zz3d.tileset.pick3DTileset(this.viewer, positions);//拾取绘制返回的模型
                    if (!tileset) {
                        Message({
                            message: '请选择模型',
                            type: 'error',
                        })
                        return;
                    }
                    this.currentAnalysisObj = new zz3d.tiles.TilesClipPlan(tileset);
                    this.mxcj_tile = this.currentAnalysisObj._tileset.name
                }
            });
    },
    // 注销分析对象
    destoryAnalysis() {
        this.viewer.zz.draw.deleteAll();
        if (this.currentAnalysisObj) {
            switch (this.currentType) {
                case 'dxkw':
                this.currentAnalysisObj.destroy()
                    break;
                case 'dbtm':
                this.currentAnalysisObj.enable = false
                    break;
                case 'mxpq':
                this.currentAnalysisObj.clear()
                    break
                case 'mxyp':
                this.currentAnalysisObj.destroy()
                    break;
                case 'mxcj':
                this.currentAnalysisObj.clear()
                    break
                default:
                this.viewer.zz.analyseFactory.remove(this.currentAnalysisObj?.id)
                this.viewer.zz.analyseFactory.removeAll()
                    break;
            }     
        }
        this.currentAnalysisObj = undefined

        this.ksy_horizontalAngle = 90
        this.ksy_verticalAngle = 60
        this.ksy_distance = 10
        this.ksy_DebugFrustum = true

        this.flfx_Height = 0
        this.flfx_MinHeight = 0
        this.flfx_MaxHeight = 0
        this.flfx_chkUnderground = false

        this.dxkw_clipHeight = 1

        this.dbtm_Underground = false
    },
    callbackClose() {
        this.$emit('close') 
        this.backAnalysis()
    }
  }
}


</script > 

<style scoped >
@import 'index.css';
.analysisBox {
    position: absolute;
    width: 300px;
    right: 105px;
    top: 50px;
}
:deep .el-slider__runway.show-input{
    margin-right:10px !important;
}
:deep .el-slider__input{
    width: 80px !important;
}
</style>